# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import pymysql


def execute(db, cursor):
    sql = """
    SELECT * FROM py_employee
    WHERE income >= %d
    """ % 1000
    try:
        cursor.execute(sql)
        resultes = cursor.fetchall()
        for row in resultes:
            fname = row[0]
            lname = row[1]
            age = row[2]
            income = row[3]
            print("fname=%s, lname=%s, age=%d, income=%d" %(fname, lname, age, income))
    except Exception as e:
        print("查询失败")
        print(e)


def connect():
    db = pymysql.connect(user="lark", password="0915", host="localhost", database="test")
    cursor = db.cursor()
    cursor.execute("SELECT VERSION()")
    data = cursor.fetchone()
    print("connect mysql : %s" % data)
    execute(db, cursor)
    db.close()


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    connect()
